<template>
  <div class="redConfig">
    <Form :model="formItem" :label-width="150" class="consumerForm">
      <div class="item-title">红包设置</div>
      <FormItem label="完善简历">
        <RadioGroup v-model="formItem.is_open">
          <Radio :label="1">开启</Radio>
          <Radio :label="0">关闭</Radio>
        </RadioGroup>
        <br />
        <span class="alert">完善简历，由平台奖励用户，用户简历达到一定百分比即可获得该奖励</span>
      </FormItem>
      <div v-if="formItem.is_open">
        <FormItem label="奖励金额">
          <InputNumber v-model="formItem.reward" placeholder="请输入奖励金额" style="width:200px" :min="1"></InputNumber>
          <span>&nbsp&nbsp元</span>
          <br />
          <span class="alert">最低金额1元，默认10元</span>
        </FormItem>
        <FormItem label="简历完整度">
          <Select v-model="formItem.complete" style="width:200px">
            <Option :value="90">只填写必填项（90%）</Option>
            <Option :value="100">全部完整填写（100%）</Option>
          </Select>
        </FormItem>
        <FormItem label="奖励描述">
          <Input v-model="formItem.description" placeholder="请输入奖励描述" style="width:200px"></Input>
          <br />
          <span class="alert">对完善简历可用一句话描述，更加吸引求职者</span>
        </FormItem>
      </div>
      <FormItem>
        <Button type="primary" @click="update">保存</Button>
      </FormItem>
    </Form>
  </div>
</template>

<script>
import { RedBagSetting, RedBagSettingUpdate } from "api/recuit/setting";
export default {
  name: "redConfig",
  data() {
    return {
      formItem: {
        is_open: 0,
        reward: 1,
        complete: 90,
        description: ""
      }
    };
  },
  components: {},
  beforeCreate() {},
  created() {},
  beforeMount() {},
  mounted() {
    this.getData();
  },
  beforeUpdate() {},
  updated() {},
  beforeDestroy() {},
  destroy() {},
  methods: {
    getData() {
      RedBagSetting()
        .then(result => {
          let { redbag_config } = result;
          this.formItem = JSON.parse(redbag_config);
        })
        .catch(err => {
          console.log(err);
        });
    },
    update() {
      let formItem = JSON.stringify(this.formItem);
      RedBagSettingUpdate({redbag_config:formItem}).then((result) => {
        this.$Message.success('保存成功')
      }).catch((err) => {
        console.log(err)
      });
    }
  }
};
</script>

<style scoped lang="less">
.redConfig {
  padding: 2%;
  background: white;
  min-height: 93vh;
  .item-title {
    margin-bottom: 20px;
    padding: 8px 16px;
    font-weight: bolder;
    background-color: #f5f5f5;
    color: #333;
  }
}
</style>
